<template>
    <div>
        <h3>病人用药修改</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>药品名称</td>
                    <td><input type="text" v-model="arr.yongYaoInfoName" /></td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="arr.keShiName">
                            <option value="">请选择</option>
                            <option v-for="item in brr" :value="item.keShiName">{{ item.keShiName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>用药日期</td>
                    <td><input type="date" v-model="arr.yongYaoInfoTime" /></td>
                </tr>
                <tr>
                    <td>病人名称</td>
                    <td><input type="text" v-model="arr.bingRenName" /></td>
                </tr>
                <tr>
                    <td>病房号码</td>
                    <td><input type="text" v-model="arr.bingRenNum" /></td>
                </tr>
                <tr>
                    <td>用药状态</td>
                    <td>
                        <input type="radio" v-model="arr.bingRenState" :value="true" name="stata" />已完成
                        <input type="radio" v-model="arr.bingRenState" :value="false" name="stata" />未开始
                    </td>
                </tr>
                <tr>
                    <td>配药医生</td>
                    <td><input type="text" v-model="arr.doctor" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="Ok" class="btn btn-info" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let router = useRouter();
let route = useRoute();

onMounted(() => {
    Fan();
    Show();

})

let arr: any = ref({
    "yongYaoInfoId": route.query.id,
    "yongYaoInfoName": "",
    "keShiName": "",
    "yongYaoInfoTime": "",
    "bingRenName": "",
    "bingRenNum": "",
    "bingRenState": '',
    "doctor": "",
    "isDel": ''
})

let brr: any = ref({})

//反填
const Fan = () => {


    axios({
        url: "/api/KeShi/YongYaoFanTian",
        method: "get",
        params: {
            id: route.query.id
        }
    })
        .then(res => {
            Object.assign(arr.value, res.data)
            arr.value.yongYaoInfoTime = res.data.yongYaoInfoTime.substring(0, 10);
        })
        .catch(err => {

        })


}




const Ok = () => {
    if (arr.value.yongYaoInfoName == "") {
        alert('药品名称不能为空');
        return;
    }
    if (arr.value.keShiName == "") {
        alert('科室不能为空');
        return;
    }
    if (arr.value.yongYaoInfoTime == "") {
        alert('用药日期不能为空');
        return;
    }
    if (arr.value.bingRenName == "") {
        alert('病人名称不能为空');
        return;
    }
    if (arr.value.bingRenNum == "") {
        alert('病房号码不能为空');
        return;
    }

    if (arr.value.doctor == "") {
        alert('配药医生不能为空');
        return;
    }

    axios({
        url: "/api/KeShi/YongYaoUpfate",
        method: "put",
        data: arr.value
    })
        .then(res => {
            if (res.data > 0) {
                alert('修改成功');
                router.push('/YongYaoShow');

            }
            else {
                alert('修改失败');
            }
        })
        .catch(err => {

        })


}


//下拉框
const Show = () => {


    axios({
        url: "/api/KeShi/KeShiShow",
        method: "get",
    })
        .then(res => {
            brr.value = res.data;
        })
        .catch(err => {

        })


}

</script>

<style scoped></style>